package org.desktop.intbox.components.treemap.layouts;

import java.awt.geom.Rectangle2D;
import java.util.Iterator;

import prefuse.action.layout.Layout;
import prefuse.visual.DecoratorItem;
import prefuse.visual.VisualItem;

/**
* Set label positions. Labels are assumed to be DecoratorItem instances,
* decorating their respective nodes. The layout simply gets the bounds
* of the decorated node and assigns the label coordinates to the center
* of those bounds.
*/
public class LabelLayout extends Layout {
    public LabelLayout(String group) {
        super(group);
    }
    public void run(double frac) {
        Iterator<?> iter = m_vis.items(m_group);
        while ( iter.hasNext() ) {
            DecoratorItem item = (DecoratorItem)iter.next();
            VisualItem node = item.getDecoratedItem();
            Rectangle2D bounds = node.getBounds();
            setX(item, null, bounds.getCenterX());
            setY(item, null, bounds.getCenterY());
        }
    }
}
